home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / CRS / crs32.d81 / examples.arc / DEL.C < prev    next >
C/C++ Source or Header  |  1989-12-01  |  1KB  |  66 lines

  1. /*  del.c
  2.     ====================================================================
  3.     del command for CS-DOS
  4.     ====================================================================
  5.     del has the advantage of allowing wildcard filespecs, so things like
  6.  
  7.         del *.arc
  8.  
  9.     will work as expected. findfirst() and findnext(), however, do not
  10.     match 1581 subdirectories or splat files, so thay cannot be deleted.
  11.     ( use >s0:splatfile instead )
  12. */
  13.  
  14. #include <stream.hpp>
  15. #include <string.h>
  16. #include <ctype.h>
  17. #include <dos.h>
  18.  
  19.  
  20. void main(int argc, char ** argv)
  21. {
  22.     int     count = 0;
  23.     FIND *  info;
  24.     char    path[20], * cp;
  25.  
  26.     for (int arg=1; arg<argc; arg++) {
  27.  
  28.         strcpy(path, argv[arg]);
  29.  
  30.         if (path[1] == ':')
  31.             cp = &path[2];
  32.         else
  33.             cp = path;
  34.  
  35.         info = findfirst(argv[arg],0);
  36.  
  37.         while(info != 0) {
  38.  
  39.             strcpy(cp,info->name);
  40.  
  41.             if (info->filetype >= FA_SEQ && info->filetype <= FA_REL) {
  42.  
  43.                 cout << str(path,-20);
  44.  
  45.                 if (unlink(path))
  46.                     cout << "Delete failed.\n";
  47.                 else {
  48.                     cout << "Deleted.\n";
  49.                     count++;
  50.                 }
  51.             }
  52.  
  53.             info = findnext();
  54.         }
  55.         arg++;
  56.     }
  57.  
  58.     cout << count << " file(s) deleted.\n";
  59.  
  60.     exit(0);
  61. }
  62.  
  63.  
  64.  
  65.  
  66.